<!DOCTYPE html>
<html lang="zh">

<head>
	<meta charset="UTF-8" />
	<title>
		分类管理
	</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
	<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
	<link rel="stylesheet" href="/app/laoha/sdk/sdk.css" />
	<link rel="stylesheet" href="/app/laoha/sdk/helper.css" />
	<link rel="stylesheet" href="/app/laoha/sdk/iconfont.css" />
	<style>
		html,
		body,
		.app-wrapper {
			position: relative;
			width: 100%;
			height: 100%;
			margin: 0;
			padding: 0;
		}

		img {
			max-width: 100%;
		}
	</style>
</head>

<body>
	<div id="root" class="app-wrapper"></div>
	<script src="/app/laoha/sdk/sdk.js"></script>
	<script type="text/javascript">
		// API相关常量
		const LIST_API = "/app/laoha/admin/cate/list";
		const CREATE_API = "/app/laoha/admin/cate/store";
		const SHOW_API = "/app/laoha/admin/cate/show";
		const DELETE_API = "delete:/app/laoha/admin/cate/delete";
		const UPDATE_API = "put:/app/laoha/admin/cate/update";
		const SELECT_API = "/app/laoha/admin/cate/select";
		const UPLOAD_FILE = "post:/app/admin/upload/file";
		const UPLOAD_IMAGE = "post:/app/admin/upload/image";
		(function () {
			let amis = amisRequire('amis/embed');
			// 通过替换下面这个配置来生成不同页面
			let amisJSON = {
				"type": "page",
				"data":<?= json_encode($params, JSON_UNESCAPED_UNICODE) ?>,
				"title": "${config.title}分类管理",
				"aside": [
					{
						"type": "tpl",
						"tpl": "<h4 class='ml-5'> 选择类别</h4>"
					},
					{
						"type": "nav",
						"name": "nav",
						"stacked": true,
						"source": "${navs}",
					}
				],
				"body": [
					{
						"type": "crud",
						"api": LIST_API,
						"autoGenerateFilter": {
							"columnsNum": 2,
							"defaultCollapsed": false,
							"showBtnToolbar": false
						},
						"quickSaveItemApi": UPDATE_API + "?ids=${ids}",
						"expandConfig": {
							"expand": "all"
						},
						"headerToolbar": [
							"reload",
							{
								"label": "新增",
								"type": "button",
								"actionType": "dialog",
								"level": "primary",
								"className": "m-b-sm",
								"align": "right",
								"visibleOn": "${rules.admin || rules.store}",
								"dialog": {
									"title": "新增表单",
									"size": "full",
									"body": {
										"type": "form",
										"api": CREATE_API,
										"body": [
											{
												"type": "hidden",
												"name": "root",
												"value": "${root}",
											},
											{
												"type": "tree-select",
												"name": "parent_id",
												"label": "选择上级",
												"labelField": "title",
												"valueField": "id",
												"showIcon": false,
												"source": SELECT_API + "?status=0&is_publish=0&root=${root}",
											},
											{
												"type": "input-text",
												"name": "title",
												"label": "分类名",
												"required": true
											},
											{
												"type": "radios",
												"name": "is_publish",
												"label": "目录或内容",
												"selectFirst": true,
												"options": [
													{
														"label": "目录",
														"value": 0,
													},
													{
														"label": "内容",
														"value": 1,
													}
												],
												"desc": "目录只可包含下级分类，不能发表内容；内容则无下级分类，可发表内容,设定后无法修改的分类"
											},
											{
												"type": "input-tag",
												"name": "groups",
												"label": "分组",
												"visibleOn": "this.is_publish === 1 && config.groups",
												"desc": "用小写逗号分隔"
											},
											{
												"type": "textarea",
												"name": "desc",
												"label": "简述"
											},
											{
												"type": "input-number",
												"name": "sort",
												"label": "排序",
												"min": 0,
												"value": 0
											},
											{
												"type": "group",
												"body": [
													{
														"type": "switch",
														"name": "is_hidden",
														"label": "是否隐藏",
														"value": 0,
														"trueValue": 1,
														"falseValue": 0
													},
													{
														"type": "switch",
														"name": "status",
														"label": "是否启用",
														"value": 0,
														"trueValue": 0,
														"falseValue": 1
													}
												]
											},
											{
												"type": "input-image",
												"name": "cover",
												"label": "封面",
												"receiver": UPLOAD_IMAGE
											},
										]
									}
								}
							},
						],
						"columns": [
							{
								"name": "title",
								"label": "分类名",
								"type": "tpl",
								"tpl": "<span class='ml-${level*4-4}'> ${is_publish ? '<i class=\"far fa-file-alt\"></i>':'<i class=\"far fa-folder\"></i>'} ${title}</span>",
								"toggled": true
							},
							{
								"name": "id",
								"label": "ID",
								"type": "text",
								"toggled": false
							},
							{
								"name": "cover",
								"label": "封面",
								"type": "image",
								"thumbMode": "cover",
								"width": "45px",
								"height": "45px",
								"enlargeAble": true,
								"toggled": true
							},
							{
								"name": "parent_id",
								"label": "上级",
								"toggled": false
							},
							{
								"name": "groups",
								"label": "分组",
								"toggled": false
							},
							{
								"name": "sort",
								"label": "排序",
							},
							{
								"name": "is_hidden",
								"label": "隐藏",
								"quickEdit": {
									"mode": "inline",
									"type": "switch",
									"trueValue": 1,
									"falseValue": 0,
									"size": "sm",
									"saveImmediately": true,
								}
							},
							{
								"name": "status",
								"label": "启用",
								"quickEdit": {
									"mode": "inline",
									"type": "switch",
									"trueValue": 0,
									"falseValue": 1,
									"size": "sm",
									"saveImmediately": true,
								}
							},
							{
								"type": "operation",
								"label": "操作",
								"width": 100,
								"fixed": "right",
								"buttons": [
									{
										"type": "button",
										"icon": "fa fa-eye",
										"tooltip": "查看",
										"actionType": "dialog",
										"dialog": {
											"title": "查看",
											"size": "full",
											"body": {
												"type": "form",
												"initApi": SHOW_API + "?id=${id}",
												"body": [
													{
														"type": "static",
														"name": "title",
														"label": "分类名"
													},
													{
														"type": "divider"
													},
													{
														"type": "static",
														"name": "groups",
														"label": "分组",
													},
													{
														"type": "divider"
													},
													{
														"type": "static",
														"name": "desc",
														"label": "简述"
													},
													{
														"type": "divider"
													},
													{
														"type": "static",
														"name": "sort",
														"label": "排序",
													},
													{
														"type": "divider"
													},
													{
														"type": "switch",
														"name": "is_hidden",
														"label": "是否隐藏",
														"trueValue": 1,
														"falseValue": 0
													},
													{
														"type": "divider"
													},
													{
														"type": "switch",
														"name": "status",
														"label": "是否启用",
														"trueValue": 0,
														"falseValue": 1
													},
													{
														"type": "divider"
													},
													{

														"label": "封面",
														"type": "image",
														"name": "cover",
														"thumbMode": "cover",
														"width": "200px",
														"height": "200px",
														"enlargeAble": true
													}
												]
											}
										}
									},
									{
										"type": "button",
										"icon": "fa fa-pencil",
										"tooltip": "编辑",
										"actionType": "dialog",
										"dialog": {
											"position": "left",
											"size": "full",
											"title": "编辑",
											"visibleOn": "${rules.admin || rules.update}",
											"body": {
												"type": "form",
												"name": "sample-edit-form",
												"initApi": SHOW_API + "?edit=1&id=${id}",
												"api": UPDATE_API + "?id=${id}",
												"body": [
													{
														"type": "tree-select",
														"name": "parent_id",
														"label": "选择上级",
														"labelField": "title",
														"valueField": "id",
														"showIcon": false,
														"source": SELECT_API + "?id=neq,${id}&status=0&is_publish=0&root=${root}",
													},
													{
														"type": "input-text",
														"name": "title",
														"label": "分类名",
														"required": true
													},
													{
														"type": "static-mapping",
														"name": "is_publish",
														"label": "目录或内容",
														"map": {
															"0": "目录",
															"1": "内容",
														},
														"desc": "目录只可包含下级分类，不能发表内容；内容则无下级分类，可发表内容的分类"
													},
													{
														"name": "groups",
														"type": "input-tag",
														"label": "分组",
														"visibleOn": "this.is_publish === 1 && config.groups",
														"desc": "用小写逗号分隔"
													},
													{
														"type": "textarea",
														"name": "desc",
														"label": "简述"
													},
													{
														"type": "input-number",
														"name": "sort",
														"label": "排序",
														"min": 0,
													},

													{
														"type": "group",
														"body": [
															{
																"type": "switch",
																"name": "is_hidden",
																"label": "是否隐藏",
																"value": 0,
																"trueValue": 1,
																"falseValue": 0
															},
															{
																"type": "switch",
																"name": "status",
																"label": "是否启用",
																"value": 0,
																"trueValue": 0,
																"falseValue": 1
															}
														]
													},
													{
														"type": "input-image",
														"name": "cover",
														"label": "封面",
														"receiver": UPLOAD_IMAGE
													}
												]
											}
										}
									},
									{
										"type": "button",
										"icon": "fa fa-times text-danger",
										"tooltip": "删除",
										"actionType": "ajax",
										"confirmText": "您确认要删除?<p class=\"text-danger\">删除分类时请确定此分类下已无文章或子目录</p>",
										"api": DELETE_API + "?id=${id}",
										"visibleOn": "${rules.admin || rules.delete}"
									}
								],
								"toggled": true
							}
						]
					}
				]
			};
			let amisScoped = amis.embed('#root', amisJSON, {}, { toastPosition: 'center' });
		})();
	</script>
</body>

</html>